﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pointandclick.Objects
{
    class InventoryItem : Draggable
    {
        string key;
        
        /// <summary>
        /// Key that matches the Trigger
        /// </summary>
        public string Key { get { return key; } }
        
        Point position;

        public Point Position
        {
            get { return position; }
            set { position = value; }
        }


        public InventoryItem(Texture2D image, String key, Point position)
            : base(image, position)
        {
            this.key = key;
            //Size of the items inside inventory should be the same?
            this.rectangle = new Rectangle(position.X, position.Y, 50, 50);
            //This is the position to which the item will always be put back to if it's dragged and doesn't hit trigger
            this.position = position;
        }

        public bool Update(MouseState mouse, List<Trigger> triggerList)
        {
            rectangle.X = position.X;
            rectangle.Y = position.Y;
            base.Update();
            foreach (Trigger trigger in triggerList)
            if (!dragging && this.rectangle.Intersects(trigger.Rectangle) && this.key == trigger.Key)
                return true;
            return false;
        }
    }
}
